<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML>
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>[${sessionScope.user}]-控制台-用户角色管理</title>
    <link rel="icon" type="image/png" href="assets/i/favicon.png">
    <link rel="apple-touch-icon-precomposed" href="assets/i/app-icon72x72@2x.png">
    <meta name="apple-mobile-web-app-title" content="Amaze UI" />
 	<link rel="stylesheet" href="assets/css/amazeui.min.css" />
    <link rel="stylesheet" href="assets/css/admin.css">
    <link rel="stylesheet" href="assets/css/app.css">
    <script src="assets/js/jquery.min.js"></script>
    <link rel="stylesheet" type="text/css" href="css/sweetalert.css">
	<script src="js/sweetalert.min.js"></script> 
	<script src="http://cdn.amazeui.org/amazeui/2.7.2/css/amazeui.min.css"></script> 
	<script src="http://cdn.amazeui.org/amazeui/2.7.2/js/amazeui.min.js"></script> 
<!-- 检测用户登录，获取登录信息 -->


<script>
		$(document).ready(function()
		{
			if(getLoginStatus() == true)
				{
				getLoginInfo();
				getGroupName();
				getUserRole();
				}
				$("#table-box").css("height","331px");
		}
		);
		
		 
		
		function getLoginStatus(success_function,fail_function)
		{
			var bol=false;
			$.ajax({
		        type:'post',
		        async:false,
		        url:'${pageContext.request.contextPath}/getLoginStatus',
		        contentType:'application/json;charset=utf-8',//指定为json类型
		        success:function(data){//返回json结果
		            if(data['status'] == "false")
		            {
		            	swal({ 
							  title: "Error!", 
							  text: "请先登陆!",
							  type: "error", 
							  confirmButtonText: "Go >>",
							  closeOnConfirm: false, 
							  showLoaderOnConfirm: true 
							},
							function(){ 
							    window.location.href = "signIn";
							});
					}
					else
					{
					bol = true;
					}
		            }});
		            return bol;
		}
		
		function getLoginInfo()
		{
			$.ajax({
		        type:'post',
		        url:'${pageContext.request.contextPath}/getLoginInfo',
		        contentType:'application/json;charset=utf-8',//指定为json类型
		        success:function(data){//返回json结果
		            $('#name').html(data['username']);
		            }});
		}
		
		function getGroupName()
		{
		$.ajax({
		        type:'post',
		        url:'${pageContext.request.contextPath}/getGroupName',
		        contentType:'application/json;charset=utf-8',//指定为json类型
		        success:function(data){//返回json结果
		            $('#userInfo').append("<br \>groupname:"+data['msg']+"<br>");
		            }});
		}
		
		function signOut()
		{
		swal({ 
			title: "注销提示？", 
			text: "有些信息需要登录以后才能查阅！", 
			type: "warning",
			showCancelButton: true, 
			confirmButtonColor: "#DD6B55",
			confirmButtonText: "确认！", 
			closeOnConfirm: false
			},
			function(){
			$.ajax({
				type:'post',
				url:'${pageContext.request.contextPath}/signOut',
				contentType:'application/json;charset=utf-8',//指定为json类型
				success:function(data){//返回json结果
				//
					if(data['status']=="success")
					{
					swal("成功！", "你的登录已被注销。", "success");
					window.location.href="home"; 
					}
					else if(data['status']=="fail")
					{
					swal("失败！", "未查询到登录信息。", "error");
					window.location.href="home";
					}
				//
				}});
		});
		}
		
		
		
		
		//点击用户名编辑窗口
		function edit()
		{
		//$(this).parent().attr("id")
				$('td .grouprole').click(function(){
				 var jsonData = {  
			            "roleid" : $(this).parent().parent().attr("id"),
			            "userid" : $(this).parent().parent().children('td').eq(1).attr("id"), 
			            "pageid" : $(this).parent().parent().children('td').eq(4).attr("id") ,
			            "url" : $(this).parent().parent().children('td').eq(4).text()
			    };
				var userid =$(this).parent().parent().attr("id");
				var pageid =$(this).parent().parent().children('td').eq(4).attr("id");
						swal({ 
				  title: "变更权限(用户组)",
				  text: ""+$(this).parent().parent().children('td').eq(2).text()+" - "+
				  $(this).parent().parent().children('td').eq(4).text()+" - ("+$(this).parent().parent().children('td').eq(6).text()+")", 
				  type: "warning", 
				  showCancelButton: true, 
				  closeOnConfirm: false, 
				  showLoaderOnConfirm: true, 
				},
				function(){ 
				//
				$.ajax({
				type:'post',
				data:JSON.stringify(jsonData),
				url:'${pageContext.request.contextPath}/updateRole',
				contentType:'application/json;charset=utf-8',//指定为json类型
				success:function(data){//返回json结果
					if(data['status']=="success")
					{
							$("#tbody").html("");
						    swal("已完成");
						    getUserRole();
					}
					else
					{
						swal("变更失败!")	
					}
				}});
				//
				});
				});
				
				
				//私有权限
				$('td .userrole').click(function(){
				 var jsonData = { 
			            "userid" : $(this).parent().parent().children('td').eq(1).attr("id"), 
			            "pageid" : $(this).parent().parent().children('td').eq(4).attr("id") ,
			            "url" : $(this).parent().parent().children('td').eq(4).text()
			    };
				var userid =$(this).parent().parent().attr("id");
				var pageid =$(this).parent().parent().children('td').eq(4).attr("id");
						swal({ 
				  title: "变更权限(用户)",
				  text: ""+$(this).parent().parent().children('td').eq(2).text()+" - "+
				  $(this).parent().parent().children('td').eq(4).text()+" - ("+$(this).parent().parent().children('td').eq(6).text()+")", 
				  type: "warning", 
				  showCancelButton: true, 
				  closeOnConfirm: false, 
				  showLoaderOnConfirm: true, 
				},
				function(){ 
				//
				$.ajax({
				type:'post',
				data:JSON.stringify(jsonData),
				url:'${pageContext.request.contextPath}/updateUserRole',
				contentType:'application/json;charset=utf-8',//指定为json类型
				success:function(data){//返回json结果
					if(data['status']=="success")
					{
							$("#tbody").html("");
						    swal("已完成");
						    getUserRole();
					}
					else
					{
						swal("变更失败!")
					}
				}});
				//
				});
				});
				
		}
		
		//select改变事件
		function cc(uid,val){
			alert();
		    alert(val);
		     }
		
		
		function getUserRole(a,b)
		{
		var user_id;
		$("#tbody").html("");
		$('#count').html("");
		var jsonData;
		if(a==null|| b==null)
		{
		 jsonData = {  
			            "pstart" :"1",
			            "psize" : "7", 
			    };
		}
		else
		{
			jsonData = {  
			            "pstart" :a,
			            "psize" : b, 
			    };
		}
		
		$.ajax({
		        type:'post',
		        url:'${pageContext.request.contextPath}/userRole',
		        data:JSON.stringify(jsonData),
		        contentType:'application/json;charset=utf-8',//指定为json类型
		        success:function(data){//返回json结果
		            for(var i=0;i<data['user'].length;i++){
		            	user_id = data['user'][i]['id'];
		            	if(data['page_info'][i]['state'] == 1)
		            		data['page_info'][i]['state'] = "<span style='color:#4db14d'><b>√</b><span>"
						else if (data['page_info'][i]['state'] == 0)
		            		data['page_info'][i]['state'] = "<span style='color:#d93c37'><b>×</b><span>"
		            	else data['page_info'][i]['state'] = "?"
					    $('#tbody').append("<tr id='"+data['role'][i]['roleid']+"'>"+
                                            "<td><input type='checkbox'></td>"+
                                            "<td id='"+data['user'][i]['id']+"'>"+(i+1)+"</td>"+
                                            "<td><a href='javascript:edit()' class='userrole'>"+data['user'][i]['username']+"</a></td>"+
                                            "<td><a href='javascript:edit()' class='grouprole'>"+data['group'][i]['groupname']+"</a></td>"+
                                            "<td id='"+data['page_info'][i]['pageid']+"' class='am-hide-sm-only'>"+data['page_info'][i]['varurl']+"</td>"+
                                            "<td class='am-hide-sm-only'>"+data['page_info'][i]['pagename']+"</td>"+
                                            "<td>"+data['page_info'][i]['state']+"</td>"+
                                            "<td>"+data['group'][i]['intor']+"</td><td><select data-am-selected class='selectbox' userid='"+data['user'][i]['id']+"' onchange='cc(this[selectedIndex].class,this[selectedIndex].value)''>"+
                                            "</select></td></tr>");  
					}

					//分页
					for(var i=1;i<data['count']+1;i++){  
					    $('#count').append("<li><a href='javascript:getUserRole("+(i-1)*7+",7)'>"+i+"</a></li>");
					}
					//
					
					$.ajax({
								type:'post',
								url:'${pageContext.request.contextPath}/getAllGroup',
								contentType:'application/json;charset=utf-8',//指定为json类型
								success:function(data){//返回json结果
									if(data['status']!="fail")
									{
									for(var i=0;i<data['groupAll'].length;i++)
										    $('.selectbox').append("<option userid='1' value='"+data['groupAll'][i]['groupid']+"'>"+data['groupAll'][i]['groupname']+"</option>");
									}
									else
									{
										swal("用户组信息获取失败,暂时无法提供更换用户组服务")
									}
								}});
					
		            }});
		            
		            
		            
		            
		            
		}
		
		
		</script>


<!-- end -->
</head>

<body data-type="generalComponents">


    <header class="am-topbar am-topbar-inverse admin-header">
        <div class="am-topbar-brand">
            <a href="javascript:;" class="tpl-logo">
                <img src="assets/img/logo.png" alt="">
            </a>
        </div>
        <div class="am-icon-list tpl-header-nav-hover-ico am-fl am-margin-right">

        </div>

        <button class="am-topbar-btn am-topbar-toggle am-btn am-btn-sm am-btn-success am-show-sm-only" data-am-collapse="{target: '#topbar-collapse'}"><span class="am-sr-only">导航切换</span> <span class="am-icon-bars"></span></button>

        <div class="am-collapse am-topbar-collapse" id="topbar-collapse">

            <ul class="am-nav am-nav-pills am-topbar-nav am-topbar-right admin-header-list tpl-header-list">
                <li class="am-dropdown" data-am-dropdown data-am-dropdown-toggle>
                    <a class="am-dropdown-toggle tpl-header-list-link" href="javascript:;">
                        <span class="am-icon-bell-o"></span> 提醒 <span class="am-badge tpl-badge-success am-round">5</span></span>
                    </a>
                    <ul class="am-dropdown-content tpl-dropdown-content">
                        <li class="tpl-dropdown-content-external">
                            <h3>你有 <span class="tpl-color-success">5</span> 条提醒</h3><a href="###">全部</a></li>
                        <li class="tpl-dropdown-list-bdbc"><a href="#" class="tpl-dropdown-list-fl"><span class="am-icon-btn am-icon-plus tpl-dropdown-ico-btn-size tpl-badge-success"></span> 【预览模块】移动端 查看时 手机、电脑框隐藏。</a>
                            <span class="tpl-dropdown-list-fr">3小时前</span>
                        </li>
                        <li class="tpl-dropdown-list-bdbc"><a href="#" class="tpl-dropdown-list-fl"><span class="am-icon-btn am-icon-check tpl-dropdown-ico-btn-size tpl-badge-danger"></span> 移动端，导航条下边距处理</a>
                            <span class="tpl-dropdown-list-fr">15分钟前</span>
                        </li>
                        <li class="tpl-dropdown-list-bdbc"><a href="#" class="tpl-dropdown-list-fl"><span class="am-icon-btn am-icon-bell-o tpl-dropdown-ico-btn-size tpl-badge-warning"></span> 追加统计代码</a>
                            <span class="tpl-dropdown-list-fr">2天前</span>
                        </li>
                    </ul>
                </li>
                <li class="am-dropdown" data-am-dropdown data-am-dropdown-toggle>
                    <a class="am-dropdown-toggle tpl-header-list-link" href="javascript:;">
                        <span class="am-icon-comment-o"></span> 消息 <span class="am-badge tpl-badge-danger am-round">9</span></span>
                    </a>
                    <ul class="am-dropdown-content tpl-dropdown-content">
                        <li class="tpl-dropdown-content-external">
                            <h3>你有 <span class="tpl-color-danger">9</span> 条新消息</h3><a href="###">全部</a></li>
                        <li>
                            <a href="#" class="tpl-dropdown-content-message">
                                <span class="tpl-dropdown-content-photo">
                      <img src="assets/img/user02.png" alt=""> </span>
                                <span class="tpl-dropdown-content-subject">
                      <span class="tpl-dropdown-content-from"> 姓名 </span>
                                <span class="tpl-dropdown-content-time">10分钟前 </span>
                                </span>
                                <span class="tpl-dropdown-content-font"> Amaze UI 的诞生，依托于 GitHub 及其他技术社区上一些优秀的资源；Amaze UI 的成长，则离不开用户的支持。 </span>
                            </a>
                            <a href="#" class="tpl-dropdown-content-message">
                                <span class="tpl-dropdown-content-photo">
                      <img src="assets/img/user03.png" alt=""> </span>
                                <span class="tpl-dropdown-content-subject">
                      <span class="tpl-dropdown-content-from"> Steam </span>
                                <span class="tpl-dropdown-content-time">18分钟前</span>
                                </span>
                                <span class="tpl-dropdown-content-font"> 为了能最准确的传达所描述的问题， 建议你在反馈时附上演示，方便我们理解。 </span>
                            </a>
                        </li>

                    </ul>
                </li>
                <li class="am-dropdown" data-am-dropdown data-am-dropdown-toggle>
                    <a class="am-dropdown-toggle tpl-header-list-link" href="javascript:;">
                        <span class="am-icon-calendar"></span> 进度 <span class="am-badge tpl-badge-primary am-round">4</span></span>
                    </a>
                    <ul class="am-dropdown-content tpl-dropdown-content">
                        <li class="tpl-dropdown-content-external">
                            <h3>你有 <span class="tpl-color-primary">4</span> 个任务进度</h3><a href="###">全部</a></li>
                        <li>
                            <a href="javascript:;" class="tpl-dropdown-content-progress">
                                <span class="task">
                        <span class="desc">Amaze UI 用户中心 v1.2 </span>
                                <span class="percent">45%</span>
                                </span>
                                <span class="progress">
                        <div class="am-progress tpl-progress am-progress-striped"><div class="am-progress-bar am-progress-bar-success" style="width:45%"></div></div>
                    </span>
                            </a>
                        </li>
                        <li>
                            <a href="javascript:;" class="tpl-dropdown-content-progress">
                                <span class="task">
                        <span class="desc">新闻内容页 </span>
                                <span class="percent">30%</span>
                                </span>
                                <span class="progress">
                       <div class="am-progress tpl-progress am-progress-striped"><div class="am-progress-bar am-progress-bar-secondary" style="width:30%"></div></div>
                    </span>
                            </a>
                        </li>
                        <li>
                            <a href="javascript:;" class="tpl-dropdown-content-progress">
                                <span class="task">
                        <span class="desc">管理中心 </span>
                                <span class="percent">60%</span>
                                </span>
                                <span class="progress">
                        <div class="am-progress tpl-progress am-progress-striped"><div class="am-progress-bar am-progress-bar-warning" style="width:60%"></div></div>
                    </span>
                            </a>
                        </li>

                    </ul>
                </li>
                <li class="am-hide-sm-only"><a href="javascript:;" id="admin-fullscreen" class="tpl-header-list-link"><span class="am-icon-arrows-alt"></span> <span class="admin-fullText">开启全屏</span></a></li>

                <li class="am-dropdown" data-am-dropdown data-am-dropdown-toggle>
                    <a class="am-dropdown-toggle tpl-header-list-link" href="javascript:;">
                        <span class="tpl-header-list-user-nick" id="name">姓名</span><span class="tpl-header-list-user-ico"> <img src="assets/img/user01.png"></span>
                    </a>
                    <ul class="am-dropdown-content">
                        <li><a href="#"><span class="am-icon-bell-o"></span> 资料</a></li>
                        <li><a href="#"><span class="am-icon-cog"></span> 设置</a></li>
                        <li><a href="javascript:signOut()"><span class="am-icon-power-off"></span> 退出</a></li>
                    </ul>
                </li>
                <li><a href="javascript:signOut()" class="tpl-header-list-link"><span class="am-icon-sign-out tpl-header-list-ico-out-size"></span></a></li>
            </ul>
        </div>
    </header>







    <div class="tpl-page-container tpl-page-header-fixed">


        <div class="tpl-left-nav tpl-left-nav-hover" style="display: none;">
            <div class="tpl-left-nav-title">
                Amaze UI 列表
            </div>
            <div class="tpl-left-nav-list">
                <ul class="tpl-left-nav-menu">
                    <li class="tpl-left-nav-item">
                        <a href="index.html" class="nav-link active">
                            <i class="am-icon-home"></i>
                            <span>首页</span>
                        </a>
                    </li>
                    <li class="tpl-left-nav-item">
                        <a href="chart.html" class="nav-link tpl-left-nav-link-list">
                            <i class="am-icon-bar-chart"></i>
                            <span>数据表</span>
                            <i class="tpl-left-nav-content tpl-badge-danger">
               12
             </i>
                        </a>
                    </li>

                    <li class="tpl-left-nav-item">
                        <!-- 打开状态 a 标签添加 active 即可   -->
                        <a href="javascript:;" class="nav-link tpl-left-nav-link-list active">
                            <i class="am-icon-table"></i>
                            <span>表格</span>
                            <!-- 列表打开状态的i标签添加 tpl-left-nav-more-ico-rotate 图表即90°旋转  -->
                            <i class="am-icon-angle-right tpl-left-nav-more-ico am-fr am-margin-right tpl-left-nav-more-ico-rotate"></i>
                        </a>
                        <ul class="tpl-left-nav-sub-menu" style="display:block">
                            <li>
                                <!-- 打开状态 a 标签添加 active 即可   -->
                                <a href="table-font-list.html" class="active">
                                    <i class="am-icon-angle-right"></i>
                                    <span>文字表格</span>
                                    <i class="am-icon-star tpl-left-nav-content-ico am-fr am-margin-right"></i>
                                </a>

                                <a href="table-images-list.html">
                                    <i class="am-icon-angle-right"></i>
                                    <span>图片表格</span>
                                    <i class="tpl-left-nav-content tpl-badge-success">
               18
             </i>

                                    <a href="form-news.html">
                                        <i class="am-icon-angle-right"></i>
                                        <span>消息列表</span>
                                        <i class="tpl-left-nav-content tpl-badge-primary">
               5
             </i>


                                        <a href="form-news-list.html">
                                            <i class="am-icon-angle-right"></i>
                                            <span>文字列表</span>

                                        </a>
                            </li>
                        </ul>
                    </li>

                    <li class="tpl-left-nav-item">
                        <a href="javascript:;" class="nav-link tpl-left-nav-link-list">
                            <i class="am-icon-wpforms"></i>
                            <span>表单</span>
                            <i class="am-icon-angle-right tpl-left-nav-more-ico am-fr am-margin-right"></i>
                        </a>
                        <ul class="tpl-left-nav-sub-menu">
                            <li>
                                <a href="form-amazeui.html">
                                    <i class="am-icon-angle-right"></i>
                                    <span>Amaze UI 表单</span>
                                    <i class="am-icon-star tpl-left-nav-content-ico am-fr am-margin-right"></i>
                                </a>

                                <a href="form-line.html">
                                    <i class="am-icon-angle-right"></i>
                                    <span>线条表单</span>
                                </a>
                            </li>
                        </ul>
                    </li>

                    <li class="tpl-left-nav-item">
                        <a href="login.html" class="nav-link tpl-left-nav-link-list">
                            <i class="am-icon-key"></i>
                            <span>登录</span>

                        </a>
                    </li>
                </ul>
            </div>
        </div>





        <div class="tpl-content-wrapper tpl-content-wrapper-hover">
            <div class="tpl-content-page-title"  style="float:left; margin-right:1%">
                管理中心
            </div>
            <ol class="am-breadcrumb">
                <li><a href="home" class="am-icon-home">首页</a></li>
                <li><a href="manage">控制台</a></li>
                <li class="am-active">用户列表</li>
            </ol>
            
<!-- -------------------------------------------------------------------------------------------------------------------- -->
            <div class="tpl-portlet-components">
                <div class="portlet-title">
                    <div class="caption font-green bold">
                        <span class="am-icon-code"></span> 列表
                    </div>
                    <div class="tpl-portlet-input tpl-fz-ml">
                        <div class="portlet-input input-small input-inline">
                            <div class="input-icon right">
                                <i class="am-icon-search"></i>
                                <input type="text" class="form-control form-control-solid" placeholder="搜索..."> </div>
                        </div>
                    </div>


                </div>
                <div class="tpl-block">
                    <div class="am-g">
                        <div class="am-u-sm-12 am-u-md-6">
                            <div class="am-btn-toolbar">
                                <div class="am-btn-group am-btn-group-xs">
                                    <button type="button" class="am-btn am-btn-default am-btn-success"><span class="am-icon-plus"></span> 新增</button>
                                    <button type="button" id="savetable" class="am-btn am-btn-default am-btn-secondary"><span class="am-icon-save"></span> 保存(.excel)</button>
                                </div>
                            </div>
                        </div>
                        <div class="am-u-sm-12 am-u-md-3">
                            <div class="am-form-group">
                                <select data-am-selected="{btnSize: 'sm'}">
              <option value="option1">所有类别</option>
              <option value="option2">IT业界</option>
              <option value="option3">数码产品</option>
              <option value="option3">笔记本电脑</option>
              <option value="option3">平板电脑</option>
              <option value="option3">只能手机</option>
              <option value="option3">超极本</option>
            </select>
                            </div>
                        </div>
                        <div class="am-u-sm-12 am-u-md-3">
                            <div class="am-input-group am-input-group-sm">
                                <input type="text" class="am-form-field">
                                <span class="am-input-group-btn">
            <button class="am-btn  am-btn-default am-btn-success tpl-am-btn-success am-icon-search" type="button"></button>
          </span>
                            </div>
                        </div>
                    </div>
                    <div class="am-g">
<!-- -------------------------------------------------------------------------------------------------------------------------------------------------------- -->
                        <div class="am-u-sm-12">
                            <form class="am-form" id="table-box">
                                <table id="table" class="am-table am-table-striped am-table-hover table-main">
                                    <thead>
                                        <tr>
                                            <th class="table-check"><input type="checkbox" class="tpl-table-fz-check"></th>
                                            <th class="table-id">ID</th>
                                            <th class="table-title">用户名</th>
                                            <th class="table-type">角色</th>
                                            <th class="table-author">资源</th>
                                            <th class="table-date">资源描述</th>
                                            <th class="table-author">权限</th>
                                            <th class="table-author">描述</th>
                                            <th class="table-author">操作</th>
                                        </tr>
                                    </thead>
                                    <tbody id="tbody">
                                        
                                    </tbody>
                                </table>

<!-- ----------------------------------------------------------------------------------------------------------------------- -->
                                <div class="am-cf">

                                    <div class="am-fr">
                                        <ul class="am-pagination tpl-pagination" id="count">
                                            <li><a href="javascript:getUserRole(7,7)">下一页</a></li>
                                        </ul>
                                    </div>
                                </div>
                                <hr>

                            </form>
                        </div>

                    </div>
                </div>
                <div class="tpl-alert"></div>
            </div>
<!-- ------------------------------------------------------------------------------------------------------------------------------ -->









        </div>

    </div>
    <script src="assets/js/amazeui.min.js"></script>
    <script src="assets/js/app.js"></script>
    <script src="js/jquery.table2excel.min.js"></script>
    
    <script>
		$(function() {
		
		    $("#savetable").click(function(){
		        $("#table").table2excel({
		            exclude: ".noExl",
		            name: "Excel Document Name",
		            filename: "TablExcel.xlsx",
		            exclude_img: true,
		            exclude_links: true,
		            exclude_inputs: true
		        });
		    });
		     
		});
</script>
    
</body>

</html>